﻿#pragma once

#include "CoreMinimal.h"
#include "RenderTexture.h"
#include "RenderTexture2D.generated.h"

/**
 * 纹理的寻址模式
 */
UENUM()
enum class ERenderTextureAddressMode
{
	/** 环绕模式 */
	TA_Wrap UMETA(DisplayName="Wrap"),
	
	/** 限制 */
	TA_Clamp UMETA(DisplayName="Clamp"),
	
	/** 镜像 */
	TA_Mirror UMETA(DisplayName="Mirror"),
};

/**
 * 纹理的采用方式
 */
UENUM()
enum class ERenderTextureFilter
{
	/** 最近点采样 */
	TF_Nearest UMETA(DisplayName="Nearest"),

	/** 双线性采样 */
	TF_Bilinear UMETA(DisplayName="Bi-linear"),

	/** 三线性采样 */
	TF_Trilinear UMETA(DisplayName="Tri-linear"),
};

/**
 * 纹理的MipMap数据
 */
USTRUCT(BlueprintType)
struct FRenderTexture2DMipMap
{
	GENERATED_BODY()

	/** 当前Mip的宽度 */
	UPROPERTY(EditAnywhere)
	int32 SizeX;
	
	/** 当前Mip的高度 */
	UPROPERTY(EditAnywhere)
	int32 SizeY;

	/** 当前Mip的图像数据 */
	UPROPERTY()
	TArray<uint8> TextureData;

public:
	FRenderTexture2DMipMap()
		: SizeX(0)
		, SizeY(0)
	{
	}
};

/**
 * BRGA格式2D渲染贴图对象
 */
UCLASS(Blueprintable, BlueprintType)
class SOFTRENDERER_API URenderTexture2D : public URenderTexture
{
	GENERATED_UCLASS_BODY()

public:
	/** X轴的纹理寻址模式 */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Texture, meta=(DisplayName="X-axis Tiling Method"))
	ERenderTextureAddressMode AddressX;

	/** Y轴的纹理寻址模式 */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Texture, meta=(DisplayName="Y-axis Tiling Method"))
	ERenderTextureAddressMode AddressY;

	/** Y轴的纹理寻址模式 */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Texture)
	ERenderTextureFilter Filter;

	/** 纹理的MipMap数据 */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Texture)
	TArray<FRenderTexture2DMipMap> Mips;

	/** 是否是SRGB的颜色数据 */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Texture)
	uint8 bSRGB : 1;

public:
	virtual FLinearColor Sample(float U, float V) override;
	
};
